﻿using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPFStudy.PrismStudy.ViewModels
{
    /// <summary>
    /// 使用IDialogService必须实现IDialogAware
    /// </summary>
    public class DialogShowViewModel : BindableBase, IDialogAware
    {
        public string Title { get; set; } = "标题";

        public event Action<IDialogResult> RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
            RequestClose?.Invoke(new DialogResult(ButtonResult.OK, new DialogParameters()
            {
                {"Value","Hello" }
            }));
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {   
            Title = parameters?.GetValue<string>("Title");
        }
    }
}
